#include "roomslistexecutor.h"

RoomsListExecutor::RoomsListExecutor(){

}

RoomsListExecutor::RoomsListExecutor(Session*s){
    session=s;
}

void RoomsListExecutor::execute(Para* cmd){
    QBool flag = QBool(false);
    foreach (Para p, cmd->getArgs())
    {
        if (p.getName() == "success")
        {
            if (p.getText() == "TRUE")
                flag=QBool(true);
            else
                flag = QBool(false);
            break;
        }
    }
    foreach (Para p, cmd->getArgs())
    {
        if (flag){
            if (p.getName() == "room")
            {
                Room* room;
                if (p.getArgs()[0].getName() == "name")
                    if (p.getArgs()[1].getText() == "TRUE")
                        room = new Room(p.getArgs()[0].getText(),true);
                    else
                        room = new Room(p.getArgs()[0].getText(),false);
                else
                    if (p.getArgs()[0].getText() == "TRUE")
                        room = new Room(p.getArgs()[1].getText(),true);
                    else
                        room = new Room(p.getArgs()[1].getText(),false);
                session->addRoom(room);
            }
        }else{
            if (p.getName() == "reason")
            {
                emit fail(p.getText());
                break;
            }
        }
        emit proceed();
    }
}
